﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OnlineStore.Bll;
using OnlineStore.Dal;

namespace OnlineStore.Gui
{
    public partial class Add : System.Web.UI.Page
    {
        AddControl addcontrol = new AddControl();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(IsPostBack==true)
            {
                if(addcontrol.isFather(txtIdFather.Text)==false)
                {
                    lblFather.Text="Bạn đã nhập sai id father";
                }
            }
        }
        

        protected void btnAdd_Click(object sender, EventArgs e)
        {

            if (addcontrol.isFather(txtIdFather.Text) == false)
            {
                lblFather.Text = "Bạn đã nhập sai id father";
            }
            else
            {
                if (txtName.Text.ToString() == string.Empty || txtIdFather.Text == string.Empty || txtColor.Text == string.Empty || txtPrice.Text == string.Empty)
                {
                    lblWarn.Text = "Bạn đã nhập thiếu";
                    lblWarn.Visible = true;
                }
                else
                {
                    tbProduct tbProduct = new tbProduct();
                    tbProduct.Product_Name = txtName.Text.ToString();
                    tbProduct.Father = Int32.Parse(txtIdFather.Text.ToString());
                    tbProduct.Type = ddlType.SelectedValue.ToString();
                    tbProduct.Size = ddlSize.SelectedValue.ToString();
                    tbProduct.Color = txtColor.Text.ToString();
                    tbProduct.Introduce = txtIntroduce.InnerText.ToString();
                    tbProduct.Detail = txtDetail.InnerText.ToString();
                    tbProduct.Price = double.Parse("0" + txtPrice.Text.ToString());
                    tbProduct.Picture = fupHinh.FileName.ToString();
                    //xu ly dua hinh vao csdl;

                    //

                    if (addcontrol.AddProduct(tbProduct.Product_Name, (int)tbProduct.Father, tbProduct.Type, tbProduct.Size, tbProduct.Color, tbProduct.Introduce, tbProduct.Detail, (double)tbProduct.Price, tbProduct.Picture))
                    {
                    }
                    else
                    {
                    }
                }
            }
        }

        protected void btnAddCancel_Click(object sender, EventArgs e)
        {
            txtName.Text = "";
            txtIdFather.Text = "";            
            txtColor.Text = "";
            txtIntroduce.InnerText = "";
            txtDetail.InnerText = "";
            txtPrice.Text = "";
        }

        protected void btnCheckIdFather_Click(object sender, EventArgs e)
        {
            if (addcontrol.isFather(txtIdFather.Text) == false)
            {
                lblFather.Text = "Bạn đã nhập sai id father";
            }
            else
            {
                //thuc hien kiem intro+detail
                //hien intro+detail
                //txtIntroduce.InnerText=
                //txtDetail.InnerText=
            }
        }

    }
}